package com.jar.exercise.集合和数据结构.arrayList去除重复元素;

import java.util.Objects;

/**
 * @author ZhangShengHao
 * @className Student
 * @description TODO
 * @date 2020/2/25 11:27
 */
public class Student implements Comparable {
	private Integer id;
	private String name;

	public Student(Integer id, String name) {
		this.id = id;
		this.name = name;
	}

	@Override
	public String toString() {
		return "Student{" +
			"id=" + id +
			", name='" + name + '\'' +
			'}';
	}

   /* @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (id != null ? !id.equals(student.id) : student.id != null) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        return result;
    }*/

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		Student student = (Student) o;
		return Objects.equals(id, student.id) &&
			Objects.equals(name, student.name);
	}

	@Override
	public int hashCode() {
		return Objects.hash(id, name);
	}

	@Override
	public int compareTo(Object o) {
		return 1;
        /*if (!(o instanceof Student)) {
            throw new RuntimeException("不是Student对象");
        }
        Student s = (Student) o;
        if (this.id > s.id) {
            return 1;
        } else if (this.id < s.id) {
            return -1;
        }else{
            return 0;
        }*/
	}
}
